//
//  HomeAPI.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/12/1.
//

import Foundation
import HandyJSON

// MARK: - 入口-首页

// MARK: - URL
let URLHomeDeptall = "/home/deptall"   /// 支行态势
let URLHomeStastic = "/home/stastic"   /// 报警、撤布妨统计
let URLHomeStateall = "/home/stateall" /// 全行态势
let URLHomeLbt = "/home/lbt" /// 轮播图

struct HomeParam: Encodable {
    var deptName: String? // 网点名称
    var type: Int?      // 类型： 0.日 1.月 3.年
    var deptId: Int64?    // 支行网点ID
    var date: String?    // 日期
    var dateType: Int?  // 类型： 0.日 1.月 3.年

    var timestamp: String?
    var signature: String?
    
    init(deptName: String? = nil, type: Int? = nil, deptId: Int64? = nil, date: String? = nil, dateType: Int? = nil) {
        self.deptName = deptName
        self.type = type
        self.deptId = deptId
        self.date = date
        self.dateType = dateType
    }
}

// MARK: - API
extension API {
    /// 支行态势【❌已废弃】
    class func getHomeDeptall(withParam _param: HomeParam, block: ResponseBlock<DeptModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLHomeDeptall, method: .get, parameters: param, modelType: DeptModal.self, resultBlock: block)
    }

    /// 报警、撤布妨统计✅已对接
    class func getHomeStastic(withParam _param: HomeParam, block: ResponseBlock<HomeStasticModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLHomeStastic, method: .get, parameters: param, modelType: HomeStasticModal.self, resultBlock: block)
    }

    /// 全行态势✅已对接
    class func getHomeStateall(withParam _param: HomeParam, block: ResponseBlock<HomeTallModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLHomeStateall, method: .get, parameters: param, modelType: HomeTallModal.self, resultBlock: block)
    }
    
    /// 轮播图
    class func getHomeLbt(withBlock block: ResponseBlock<HomeLbtModal>?) {
        let param = getSign()
        NetManager.request(url: URLHomeLbt, method: .get, parameters: param, modelType: HomeLbtModal.self, resultBlock: block)
    }
}

// MARK: - Modals
// 全行态势
struct HomeTallModal: HandyJSON {
    var patorlPercent: HomeTallItemModal?
    var repairPercent: HomeTallItemModal?
    var yjczTotal: HomeTallItemModal?
    var bazgl: HomeTallItemModal?
    var baPercent: HomeTallItemModal?
    var lzPercent: HomeTallItemModal?
    var bookPercent: HomeTallItemModal?
}

struct HomeTallItemModal: HandyJSON {
    var wcl: Double = 0.0
    var qsbl: Double = 0.0
}

// 报警、撤布妨统计
struct HomeStasticModal: HandyJSON {
    var uncbfTotal: Int64?  // 今日撤防总数（左）
    var alarmCount: Int64?  // 今日报警总数
    var repairCount: Int64? // 今日报修总数
    var cbfTotal: Int64?    // 今日布防总数（右）
}

// 轮播图
struct HomeLbtModal: HandyJSON {
    var id: String? //主键ID
    var cover: String? // 封面图地址
    var sftz: String?  // 是否跳转 Y 是  N 否
    var tzlx: String?  // 跳转类型
    var tzcs: String?  // 跳转参数
    var isTmp: Bool?
}
